<?php
class Process_journal extends CI_Model {

	function __construct()
	{
		parent::__construct();
	}

	function upload_journal()
	{
		//Check for user loged in

		//Validate fields

		//Upload paper

		$config['upload_path'] = './application/journaluploads/';
		$config['allowed_types'] = '*';
		$config['max_size']	= '10000';
		$config['encrypt_name'] = true;


		$this->load->library('upload');
		$this->upload->initialize($config);

		if ( ! $this->upload->do_upload("journalUpload"))
		{
			$error = array('error' => $this->upload->display_errors());
			//$this->load->view('upload_form', $error);
		}
		else
		{

			$upload_data = $this->upload->data();


			//Upload paper thumbnail
			$config2['upload_path'] = './application/journaluploads/thumbs/';
			$config2['allowed_types'] = 'gif|jpg|png';
			$config2['max_size']	= '10000';
			$config2['file_name'] = $upload_data['file_name'];
			$config2['encrypt_name'] = false;

			/*
			 $this->upload->set_upload_path($config2['upload_path']);
			 $this->upload->set_filename($config2['upload_path'], $config2['file_name']);
			 $this->upload->set_allowed_types($config2['allowed_types']);
			 $this->upload->file_name = $config2['file_name'];
			 $this->upload->encrypt_name = false;
			 	
			 	
			 $this->upload->initialize($config2);
			 	
			 $this->upload->do_upload("imageUpload");
			 $error = array('error' => $this->upload->display_errors());
			 echo "step 2";
			 print_r($error);
			 */
			//Insert uploads
				
			date_default_timezone_set('Asia/Kolkata');

			$data = array(
			   'name' =>  $this->input->post('paper_name'),
			   'abstract' =>  $this->input->post('abstract'),
			   'description' =>  $this->input->post('description'),
			   'pub_date' =>  $this->input->post('pub_date'),
			   'isbn' =>  $this->input->post('isbn'),
			   'pages' =>  $this->input->post('pages'),
			// 'author_user_ref' =>  $this->input->post('title'),
				'posted_date' =>  date("Y-m-d H:i:s",strtotime("now")),
				'posted_by' =>  $this->sessionfunctions->getSessionUserId(),
			   'subject_ref' =>  $this->input->post('subject_ref'),
			// 'main_subject_ref' =>  $this->input->post('main_subject_ref'),
				'paper_filename' =>  $upload_data['file_name']
			);
			$this->db->insert('tbl_paper', $data);


			$genPaperId = $this->db->insert_id();
				
			//Insert second author
			$data1 = array(
			   'first_name' =>  $this->input->post('author2name'),
			   'email' =>  $this->input->post('author2email'),
			   'phone_number' =>  $this->input->post('author2phone'),
			   'address' =>  $this->input->post('author2address'),
			   'designation' =>  $this->input->post('author2designation'),
			   'for_paper' =>   $genPaperId
			);
			$this->db->insert('tbl_support_author', $data1);


			//Insert third author
			$data1 = array(
			   'first_name' =>  $this->input->post('author3name'),
			   'email' =>  $this->input->post('author3email'),
			   'phone_number' =>  $this->input->post('author3phone'),
			   'address' =>  $this->input->post('author3address'),
			   'designation' =>  $this->input->post('author3designation'),
			   'for_paper' =>   $genPaperId
			);
			$this->db->insert('tbl_support_author', $data1);

		}
	}
}

?>